package com.huike.review.vo;


import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;

/**
 * 用户VO类
 * 所谓的VO即ViewObject
 * 前端往后端传递的对象和后端返回前端的对象都叫VO
 * 即前端的可视化对象，用于给前端返回数据
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
public class MybatisReviewVO<T> implements Serializable {


    private Integer code; //编码：1成功，0和其它数字为失败
    private String msg; //错误信息
    private T data; //数据

    public static <T> MybatisReviewVO<T> success(T data) {
        MybatisReviewVO<T> mybatisReviewVO  = new MybatisReviewVO<T>();
        mybatisReviewVO.data = data;
        mybatisReviewVO.code = 1;
        return mybatisReviewVO;
    }

    public static <T> MybatisReviewVO<T> error(String msg) {
        MybatisReviewVO mybatisReviewVO = new MybatisReviewVO();
        mybatisReviewVO.msg = msg;
        mybatisReviewVO.code = 0;
        return mybatisReviewVO;
    }
}